package com.dongge.service;

import com.dongge.dao.CURDDaoBase;
import com.dongge.entity.Department;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/11/3.
 */
@Service
public class DepartmentService extends CURDDaoBase<Department> {

    /**
     * 获取父节点下目录列表
     * @param parentId
     * @return
     */
    public List<Department> findDepartmentsByParentId(Long parentId){
        if(parentId == null)
        {
            String hsql = "from Department d where d.parent is null order by d.name desc";
            return getSession().createQuery(hsql)
                    .list();
        }
        String hsql = "from Department d where d.parent.id = :id order by d.name desc";
        return getSession().createQuery(hsql)
                .setLong("id",parentId)
                .list();
    }
}
